/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package treeship.core.service.impl;

import java.util.Map;
import java.util.Random;

import treeship.core.archetype.ArchetypeShip;
import treeship.core.exceptions.CantDoThatException;
import treeship.core.service.Nexus;
import treeship.core.service.ShipFactory;
import treeship.core.ship.impl.TreeShip;

/**
 * 
 * @author Moonchild
 */
public class ShipFactoryImpl extends ShipFactory<TreeShip> {

	public ShipFactoryImpl() {
	}

	@Override
	public TreeShip buildShip(String type, Long seed, Map<String, Double> values)
			throws CantDoThatException {

		if (seed == null) {
			seed = new Random().nextLong();
		}
		ArchetypeShip archetypeShipFor = Nexus.getRepository()
				.getArchetypeShipFor(type);
		if (archetypeShipFor == null) {
			CantDoThatException.cantDo(type
					+ " is not an object in the hierarchy, check the spelling");
		}
		TreeShip ship = new TreeShip(archetypeShipFor, seed, values);
		ship.createChildren();
		return ship;
	}

}
